package nl.ViewerServer.ServerManager;

import nl.ViewerServer.Database.DatabaseConnection;
import nl.ViewerServer.ServerManager.DataManager.DataManager;
import nl.ViewerServer.ServerManager.JobManager.JobManager;
import nl.ViewerServer.ServerManager.UserManager.UserManager;

import org.apache.log4j.Logger;

public class ServerManager {
   private static Logger              log = Logger.getLogger( ServerManager.class );
   private static ServerManager       instance;
   public static DatabaseConnection   database;
   public static UserManager          userManager;
   public static DataManager          dataManager;
   public static JobManager           jobManager;                                   // the manager responsible for

   // carrying out jobs

   public synchronized static ServerManager getInstance() {
      if( instance == null ) {
         try {
            instance = new ServerManager();
         }
         catch( Exception e ) {
            log.fatal( "Error while instantiating ServerManager instance", e );
            return null;
         }
      }
      return instance;
   }

   private ServerManager() throws Exception {
      log.info( "ServerManager starting..." );

      userManager = new UserManager();

      dataManager = new DataManager();

      jobManager = new JobManager();

      database = new DatabaseConnection();

      database.initialize();

      log.info( "ServerManager started." );
   }

   public void shutdown() {
      jobManager.shutdown();

   }

}
